/*
 * Famon (http://code.google.com/p/famon/)
 * Copyright (c) 2010 Carl Crous.
 *
 * This file is part of Famon.
 *
 * Famon is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Famon is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Famon.  If not, see <http://www.gnu.org/licenses/>.
 */

package za.org.foobar.famon.model;

/**
 *
 */
public class RoleEnum {
    public static final int USER = 1 << 0;
    public static final int ADMIN = 1 << 1;

    public static boolean hasRole(int compoundRole, int singleRole) {
        return (compoundRole & singleRole) != 0;
    }

    public static int user() {
        return USER;
    }

    public static int admin() {
        return USER | ADMIN;
    }

    public static int fromString(String str) {
        if (str.equalsIgnoreCase("admin")) {
            return ADMIN;
        }
        return USER;
    }

    public static String toString(int role) {
        switch (role) {
            case USER | ADMIN: return "Admin";
            default:
            case USER: return "User";
        }
    }
}
